< previous page page_182 next page >

Page 182
e10a6a0a59f035e870d90cca05b85fce.gif
                .rgbBlue = b
            End With
        Next X
    Next Y 

    ' Set picResult's pixels.
    SetBitmapPixels picResult, bits_per_pixel, pixels
    picResult.Picture = picResult.Image

    ' Show the new brightness histogram.
    ShowHistograms picResult, False
End Sub
Unfortunately, the techniques used by program Contrast do not always offer a perfect solution. In some images, the component histograms are not evenly distributed. For example, an image's red component values might be grouped in two clumps, one on the histogram's left and one on the histogram's right. That grouping could produce an image with some parts that are too red and other parts that are not red enough.
In that case, spreading the values out so that they span the range 0 to 255 will not make much difference because the values already span most of that range. Spreading the values out farther will make many fall outside the range 0 to 255, so many will be adjusted to 0 or 255. That will remove the differences between those colors and will reduce contrast for parts of the image.
A better strategy would be to spread the values in the two clumps more smoothly through the existing component range.
Still other images might require other techniques for remapping color component values to achieve the best effect. No single strategy will always produce an ideal result.
Binary Contrast Enhancement
If you use the Contrast program described in the previous section to spread color values too far, many will fall outside the range 0 to 255 and will be adjusted to one of those two values. If you stretch the colors far enough, you may get an image in which every pixel is either black or white.
Binary contrast enhancement performs this operation intentionally. It examines each pixel in an image and compares the pixel's brightness to a cutoff value. It makes pixels that are brighter than the cutoff value white. It makes the other pixels black. The result can often separate two parts of the image that differ in brightness by only a small amount.
Example program BinCont, shown in Figure 6.8, performs binary contrast enhancement. When you click on a position in the image's brightness histogram, BinCont compares the pixels' brightness value to the value you clicked. It makes pixels that are brighter than the value you clicked white and it makes the others black.
Program BinCont is similar to many of the other programs described in this chapter. The main difference is in the TransformImage subroutine shown in the following code. This

 
< previous page page_182 next page >